package com.ustadzmenjawab.twitter;

import java.util.List;

import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.UserList;
import twitter4j.conf.ConfigurationBuilder;

import com.ustadzmenjawab.conf.Configuration;
import com.ustadzmenjawab.db.DBAccess;
import com.ustadzmenjawab.util.TwitterUtil;

public class TwitterListCrawler {

	public static void main(String[] args) {
		ConfigurationBuilder cb = new ConfigurationBuilder();
		cb.setDebugEnabled(true)
		.setIncludeRTsEnabled(true)
		.setIncludeEntitiesEnabled(true)
		.setOAuthConsumerKey(Configuration.getProperty("REST_OAUTH_CONSUMER_KEY"))
		.setOAuthConsumerSecret(Configuration.getProperty("REST_OAUTH_CONSUMER_SECRET"))
		.setOAuthAccessToken(Configuration.getProperty("REST_OAUTH_ACCESS_TOKEN"))
		.setOAuthAccessTokenSecret(Configuration.getProperty("REST_OAUTH_ACCESS_TOKEN_SECRET"));
		twitter4j.conf.Configuration twconf = cb.build();
		Twitter restAPI = new TwitterFactory(twconf).getInstance();
		
		DBAccess db = new DBAccess();
		List<Integer> listIDs = db.getUserListID();
		for(Integer id : listIDs){
			try{
				 TwitterUtil.checkHitLimit(restAPI);
				 UserList ul = restAPI.showUserList(id);
				 System.out.println("insert list profile: " + ul.getFullName());
				 db.inserUserListInfo(ul);
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}

}
